<?php
	include "core/mysql.php";
	//1、做好数据的校验
 $arr = array();
 
 if(empty($_GET['name'])){
	 $arr['code'] = -10001;
	 $arr['message'] = "对不起！用户不正确";	
	 echo json_encode($arr);
	 exit();
 }
 if(empty($_GET['pass'])){
	 $arr['code'] = -10002;
	 $arr['message'] = "对不起！密码不正确";	
	 echo json_encode($arr);
	 exit();
 }
if(empty($_GET['shuoshuo'])){
	 $arr['code'] = -10003;
	 $arr['message'] = "对不起！";	
	 echo json_encode($arr);
	 exit();
 }
 if(empty($_GET['email'])){
	 $arr['code'] = -10004;
	 $arr['message'] = "对不起！";	
	 echo json_encode($arr);
	 exit();
 }

//2、获取到页面传过来的用户名、密码
$name = $_GET['name'];
$pass = $_GET['pass'];
$shuoshuo = $_GET['shuoshuo'];
$email = $_GET['email'];
$touxiang = $_GET['touxiang'];

$sqlname = "select * from tbl_user where `name` = '$name' ";
//3、把用户、密码和年龄组成一条可以插入的SQL语句
$sql = "INSERT INTO tbl_user(`name`,password,string,email,touxiang_img) VALUES('{$name}','{$pass}','{$shuoshuo}','{$email}','{$touxiang}')";

//4、把数据库连接上
//$link = new mysqli("127.0.0.1",'root',"","news");
////出现了乱码
//mysqli_set_charset($link, 'utf8');
//封装连接数据库
connect();

$resname = mysqli_query($link, $sqlname);
if(mysqli_num_rows($resname)>0){
				$arr['code'] = -10006;
				$arr['message'] = "用户名已存在";	
				echo json_encode($arr);
	}else{

//5、执行插入语句
$res = mysqli_query($link, $sql);
//判断影响的行数是不是大于0
if(mysqli_affected_rows($link)>0){
	
	//6、提醒用户注册成功
	$arr['code'] = 1;
	$arr['message'] = "注册成功";	
	echo json_encode($arr);
}else{
	$arr['code'] = -10005;
	$arr['message'] = "注册失败";	
	echo json_encode($arr);
}

}

//7、关闭数据库
mysqli_close($link);
